#include "sos.h"
#include <malloc.h>

//return a semaphore. Initialize it with the total
//number of concurrent processes that can access 
//the resource.
semaphore create_semaphore(unsigned char access_limit)
{
	semaphore sem = (semaphore) malloc(sizeof(unsigned char));
	*sem = access_limit;
	return sem;
}
bit sem_acquire(semaphore sem)
{
	EA = 0;
	if(*sem <= 0)
		return 0;
	*sem--;
	EA = 1;
	return 1;
}

void sem_release(semaphore sem)
{
	EA = 0;
	*sem++;
	EA = 1;
}

